﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PJ.Business.Partner;
using PJ.Business;
using Microsoft.Practices.Composite.Events;
using System.Windows;

namespace PJ.Presentation.Partner
{
    public abstract class PartnerModel : ItemViewModel, IPartnerModel
    {
        public PartnerModel(IView view, IEventAggregator aggregator, IPartnerService service)
            : base(view, aggregator, service)
        {
        }

        /// <summary>
        /// GetValues. Sets the businness object properties using the model property values
        /// </summary>
        /// <param name="businessObject">business object to update</param>
        public override IBusinessObject GetValues(IBusinessObject businessObject)
        {
            base.GetValues(businessObject);
            IPartner val = (IPartner)businessObject;
            val.Phone = Phone; 
            val.Address = Address;
            return businessObject;
        }
        /// <summary>
        /// SetValues. Sets the model properties using the businessobject property values
        /// </summary>
        /// <param name="businessObject"></param>
        public override void SetValues(IBusinessObject businessObject)
        {
            base.SetValues(businessObject);
            IPartner val = (IPartner)businessObject;
            Phone = val.Phone;
            Address = val.Address;
        }

        public string Phone
        {
            get { return (string)ThreadUnsafeGetValue(PhoneProperty); }
            set { ThreadUnsafeSetValue(PhoneProperty, value); }
        }

        public static readonly DependencyProperty PhoneProperty =
            DependencyProperty.Register("Phone", typeof(string), typeof(PartnerModel), new UIPropertyMetadata(""));

        public string Address
        {
            get { return (string)ThreadUnsafeGetValue(AddressProperty); }
            set { ThreadUnsafeSetValue(AddressProperty, value); }
        }

        public static readonly DependencyProperty AddressProperty =
            DependencyProperty.Register("Address", typeof(string), typeof(PartnerModel), new UIPropertyMetadata(""));

    }
}
